import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

class Solution {
    public boolean canPermutePalindrome(String s) {
        char[] chars = s.toCharArray();
        HashMap<Character, Integer> map = new HashMap<>();
        int len = chars.length;
        while (len > 0) {
            char flag = chars[len - 1];
            if (map.containsKey(flag)) {
                len--;
            } else {
                int count = 0;
                for (int i = len - 1; i >= 0; i--) {
                    if (chars[i] == flag) {
                        count++;
                    }
                }
                map.put(flag, count);
                len--;
            }
        }
        int a=0;
        int b=0;
        for (int i=0;i<chars.length;i++) {
            if(map.containsKey(chars[i])){
                a=map.remove(chars[i]);
                if(a%2!=0){
                    b++;
                }
                if(b>1){
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        String s = "as";
        Solution solution=new Solution();
        boolean ret=solution.canPermutePalindrome(s);
        System.out.println(ret);
    }
}
